package com.qf.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.qf.entity.User;
import com.qf.resp.ResultEntity;
import com.qf.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/userController")
public class UserController {

    @RequestMapping("/hello")
    public String hello() {
        return "hello";
    }

    @Autowired
    private IUserService userService;

    @RequestMapping("/addUser")
    public ResultEntity addUser(@RequestBody User user) {
        return ResultEntity.success(userService.insert(user));
    }

    @RequestMapping("/getUserPage")
    public Page<User> getUserPage(@RequestBody Page<User> page){
        return userService.selectPage(page);
    }

    @RequestMapping("/getUserByUsername")
    public User getUserByUsername(String username){
        EntityWrapper<User> wrapper = new EntityWrapper<>();
        wrapper.eq("username",username);
        User user = userService.selectOne(wrapper);
        return user;
    }
}
